<?php

use yii\helpers\Html;
use kartik\grid\GridView;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use common\models\Expert\Expert;

/* @var $this yii\web\View */
/* @var $searchModel common\models\Expert\ExpertSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', '专家列表');
$this->params['breadcrumbs'][] = $this->title;
?>
<?php $this->beginBlock('siderbar'); ?>
<?= $this->render('//layouts/exp-menu') ?>
<?php $this->endBlock(); ?>
<div class="expert-index">
    <!-- <h1><?= Html::encode($this->title) ?></h1> -->
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
    <p>
        <?= Html::a(Yii::t('app', '新增'), ['create'], ['class' => 'btn btn-success']) ?>
        <button class="btn btn-danger" id="alldel" type="button">删除</button>
        <button class="btn btn-warning" type="button" data-toggle="modal" data-target="#myModal">导入</button>
    </p>
    <?= GridView::widget([
            'id' => "myform",
            'pjax'=>false,
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'containerOptions'=>['style'=>'overflow: auto'], // only set when $responsive = false
            'headerRowOptions'=>['class'=>'kartik-sheet-style'],
            'filterRowOptions'=>['class'=>'filters'],
            'panel'=>[
                'heading'=>'<h3 class="panel-title"><i class="glyphicon glyphicon-globe"></i> 数据列表</h3>',
                'type'=>'default',
                'footer'=>false
            ],
            'toolbar' => [],
            'pager'=>[
                'options'=>['class'=>'hidden']//关闭自带分页
            ],
            'persistResize'=>false,

            'columns' => [
                [
                    'class'=>'kartik\grid\CheckboxColumn',
                    'headerOptions'=>['class'=>'my-table'],
                ],

            'id',
            'username',
            //'password',
            'sex',
            'phone',
           // 'zhaopian',
             'telephone',
             'email:email',
             'compamy',
             'zhiwu',
            // 'birthday',
            // 'comefrom',
            // 'bnumber',
            // 'loc_town',
            // 'chengguo',
            // 'reason',
                [
                    'class' => 'yii\grid\ActionColumn',
                    'header' => '操作', 
                    'template' => '{view}{update}{delete}',
                    'headerOptions' => ['width' => '200'],
                    'buttons' => [
                        'view' => function ($url, $model, $key) {
                            return  Html::a('&nbsp;&nbsp;<span class="glyphicon glyphicon-eye-open" ><span class="classformat">查看</span></span>', $url, ['title' => '查看'] ) ;
                        },
                        'update' => function ($url, $model, $key) {
                            return Html::a('&nbsp;&nbsp;<span class="glyphicon glyphicon-pencil"><span class="classformat">修改</span></span>', $url, ['title' => '修改'] ) ;
                        },
                        'delete' => function ($url, $model, $key) {
                            return Html::a('&nbsp;&nbsp;<span class="glyphicon glyphicon-trash" ><span class="classformat">删除</span></span>', $url, [
                                'title' => '删除',
                                'data'=>[
                                    'confirm'=>'你确定要删除'.$model->username.'吗？',
                                    'method'=>'post'
                                ]
                            ] ) ;
                        },
                ],
                ],
            ],
        ]); ?>
        <?= \backend\components\GoLinkPager::widget([
        'pagination' => $dataProvider->pagination,
        'go' => true,
        ]); ?>

        <!-- 模态框（Modal） -->  
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">  
            <div class="modal-dialog">  
                <div class="modal-content">  
                    <div class="modal-header">  
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>  
                        <h4 class="modal-title" id="myModalLabel">导入Excel文件</h4>  
                    </div>  
                    <div class="modal-body">
                        <form id="daorua" action="<?= yii\helpers\Url::to(['expert/daoru'])?>" enctype="multipart/form-data" method="post">
                            <input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
                            <label>导入Excel文件</label>
                            <a href="<?= Yii::$app->params['excelfile'].'demo.xls'; ?>">下载模板</a>
                            <input name="excelfile" type="file" />
                        </form>
                    </div>  
                     
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>  
                        <button type="button" class="btn btn-primary" id="daoru">导入</button>
                    </div>

                </div>  
                <!-- /.modal-content -->  
            </div>  
            <!-- /.modal -->  
        </div>
</div>
<?php $this->beginBlock('footer_scripts'); ?>
<script>
    $(document).ready(function(){
        $("#daoru").on('click', function(){
            $("#daorua").submit();
        });
    });
</script>
<script>
 $(document).ready(function(){
    binddel("<?php echo Url::to(['expert/alldelete']);?>");
});
</script>
<?php $this->endBlock(); ?>